#include<bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<string> a(n);
map<int,int> mp;
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> b(m);
for(int i = 0; i < m; i++) {
int x;
cin >> x;
b[i] = x-1;
mp[x-1] ++;
}
int l=-1;
for(auto i:b) {
int l1 = a[i].length();
if(l==-1) {
l = l1;
}
else {
if(l1 != l) {
//cout << "yes1";
cout << "No";
return 0;
}
}
}
vector<char> c(l,'?');
for(int i = 0; i < l; i++) {
char c1 = '#';
bool f = 1;
for(int j = 0; j < m; j++) {
if(c1=='#') {
c1 = a[b[j]][i];
}
else {
if(a[b[j]][i] != c1) {
f = 0;
break;
}
}
}
if(f) {
c[i] = c1;
}
}
/*for(auto i:c) {
cout << i;
}*/
bool f2 = 1;
for(int i = 0; i < n; i++) {
if(mp[i]>0) {
continue;
}
if(a[i].length() != l) {
continue;
}
bool f1 = 1;
for(int j = 0; j < l; j++) {
if(c[j]=='?') {
continue;
}
if(c[j] != a[i][j]) {
f1 = 0;
break;
}
}
if(f1) {
f2 = 0;
}
}
if(!f2) {
//cout << "yes2";
cout << "No";
}
else {
cout << "Yes" << endl;
for(int i = 0; i < l; i++) {
cout << c[i];
}
}
}
1569C - Jury Meeting | 108A - Palindromic Times |
46A - Ball Game | 114A - Cifera |
776A - A Serial Killer | 25B - Phone numbers |
1633C - Kill the Monster | 1611A - Make Even |
1030B - Vasya and Cornfield | 1631A - Min Max Swap |
1296B - Food Buying | 133A - HQ9+ |
1650D - Twist the Permutation | 1209A - Paint the Numbers |
1234A - Equalize Prices Again | 1613A - Long Comparison |
1624B - Make AP | 660B - Seating On Bus |
405A - Gravity Flip | 499B - Lecture |
709A - Juicer | 1358C - Celex Update |
1466B - Last minute enhancements | 450B - Jzzhu and Sequences |
1582C - Grandma Capa Knits a Scarf | 492A - Vanya and Cubes |
217A - Ice Skating | 270A - Fancy Fence |
181A - Series of Crimes | 1638A - Reverse |